<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <title>用户信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/my.css" media="all">

</head>

<body>
    <div class="layui-fluid" id="LAY-component-grid-list">

        <button class="layui-btn layui-btn-normal" id='add'><i class="layui-icon">&#xe61f;</i>新增用户</button>
        <!--		
				  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;搜索用户：
				  <div class="layui-inline">
					<input class="layui-input" name="keyword" id="keyword" autocomplete="off" placeholder="请输入用户名称">
				  </div>
				  <button class="layui-btn layui-btn-normal" data-type="reload" id="serch"><i class="layui-icon">&#xe615;</i> 搜索</button> -->
        <table id="demo" lay-filter="test"></table>
    </div>
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>停用</a>
    </script>
    <script>
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index']);
        layui.use('laydate', function() {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#datetime' //指定元素
            });
        });
        var cols =
            layui.use('table', function() {
                var table = layui.table;
                var $ = layui.$;

                table.render({
                    elem: '#demo',
                    height: 'full-80',
                    url: '../../../Users/select',
                    limit: 20,
                    cols: [
                        [ //表头
                            {
                                field: 'loginname',
                                title: '登录名',
                                width: 120,
                                event: 'info'

                            }, {
                                field: 'employname',
                                title: '员工姓名',
                                width: 200

                            }, {
                                field: 'isadmin',
                                title: '是否管理员',
                                width: 220,
                                templet: function(d) {
                                    if (d.isadmin == "1") {
                                        return "是";
                                    } else {
                                        return "否"
                                    }
                                }

                            }, {
                                fixed: 'right',
                                title: '操作',
                                width: 200,
                                align: 'center',
                                toolbar: '#barDemo'
                            }
                        ]
                    ],
                    skin: 'row', //表格风格				
                    even: true,
                });
                table.on('tool(test)', function(obj) {
                    var d = obj.data;
                    //console.log(d);
                    if (d.flag == 0) {
                        if (obj.event === 'edit' || obj.event === 'info') {
                            layer.open({
                                type: 2,
                                area: ['850px', '660px'],
                                offset: 'auto',
                                title: ['用户信息', 'background:#1e9fff;color:white;font-size:17px;font-weight:bold'],
                                content: 'useredit.html',
                                success: function(layero, index) {
                                    var body = layer.getChildFrame('body', index);
                                    body.find("input[name='loginname']").val(d.loginname);
                                    body.find("input[name='employname']").val(d.employname);
                                    body.find("#userid").val(d.userid);
                                    var list = new Array();
                                    var arr = new Array();
                                    for (var i = 0; i < body.find(":input[title]").length; i++) {
                                        list[i] = body.find(":input[title]")[i].name;
                                    }
                                    for (var j in d) {
                                        if (list.indexOf(j) != -1 && d[j] == 1) {
                                            body.find("input[name='" + j + "']").prop("checked", true);
                                        }
                                    }

                                }
                            })
                        } else if (obj.event === 'del') {
                            layer.confirm('是否确认停用', function(index) {
                                $.ajax({
                                    url: '../../../Users/del',
                                    datatype: 'json',
                                    data: {
                                        ids: d.userid
                                    },
                                    success: function(res) {
                                        if (res.data == 'ok') {
                                            layer.msg('停用成功', {
                                                offset: 'auto',
                                                icon: 1,
                                                time: 1500,
                                                end: function() {
                                                    layer.close(index); // 关闭layer
                                                    window.location.reload()
                                                }
                                            })
                                        } else if (res.data == '无权限') {
                                            layer.msg('没有权限，停用失败', {
                                                offset: 'auto',
                                                icon: 2,
                                                time: 1000
                                            })
                                        } else {
                                            layer.msg('停用失败', {
                                                offset: 'auto',
                                                icon: 2,
                                                time: 1000
                                            })
                                        }

                                    },
                                });
                            });
                        }
                    } else {
                        layer.msg('该用户已经停用，无法进行操作', {
                            offset: 'auto',
                            icon: 2,
                            time: 1500
                        });
                    }
                });
                $("#add").on('click', function() {
                        layer.open({
                            type: 2,
                            area: ['850px', '660px'],
                            offset: 'auto',
                            title: ['新增用户', 'background:#1e9fff;color:white;font-size:17px;font-weight:bold'],
                            content: 'useradd.html',
                            success: function(layero, index) {
                                var body = layer.getChildFrame('body', index);
                            }
                        })


                    })
                    /*
                    $("#serch").on('click',function(){
                    	table.reload('demo',{
                    	  url: '../../../Users/select'
                    	  ,where: {keyword:$("#keyword").val(),
                    	 
                    	  }, //设定异步数据接口的额外参数
                    	 page:{
                    		curr:1
                    	 }
                    	});
                    	$("table tr").css({"background":"#1e9fff","color":"white"});
                    });*/

                $("table tr").css({
                    "background": "#1e9fff",
                    "color": "white"
                });

            });
    </script>
</body>

</html>